/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.elec.bulk.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.elec.bulk.entity.ElecBulkManage;
import cn.net.ecode.elec.bulk.service.ElecBulkManageService;

/**
 * 团购Controller
 * @author AlanShelby
 * @version 2019-09-27
 */
@Controller
@RequestMapping(value = "${adminPath}/bulk/elecBulkManage")
public class ElecBulkManageController extends BaseController {

	@Autowired
	private ElecBulkManageService elecBulkManageService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ElecBulkManage get(String id, boolean isNewRecord) {
		return elecBulkManageService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("bulk:elecBulkManage:view")
	@RequestMapping(value = {"list", ""})
	public String list(ElecBulkManage elecBulkManage, Model model) {
		model.addAttribute("elecBulkManage", elecBulkManage);
		return "elec/bulk/elecBulkManageList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("bulk:elecBulkManage:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<ElecBulkManage> listData(ElecBulkManage elecBulkManage, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ElecBulkManage> page = elecBulkManageService.findPage(new Page<ElecBulkManage>(request, response), elecBulkManage); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("bulk:elecBulkManage:view")
	@RequestMapping(value = "form")
	public String form(ElecBulkManage elecBulkManage, Model model) {
		model.addAttribute("elecBulkManage", elecBulkManage);
		return "elec/bulk/elecBulkManageForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("bulk:elecBulkManage:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(ElecBulkManage elecBulkManage) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, elecBulkManage)){
			return renderResult(Global.FALSE, message);
		}
		elecBulkManageService.save(elecBulkManage);
		return renderResult(Global.TRUE, "保存团购成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("bulk:elecBulkManage:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(ElecBulkManage elecBulkManage) {
		elecBulkManageService.delete(elecBulkManage);
		return renderResult(Global.TRUE, "删除团购成功！");
	}

}